<?php get_instance()->view('common/header');?>
<style type="text/css">
    .portrait{max-width: 100%}
</style>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> <?php echo $title?></h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li class="btn-group"> <a class="btn default ml_5 return" href="<?php echo getUrl('config/postalCard');?>"><i class="fa fa-chevron-left"></i> 返回</a> </li>
                        <li> <i class="fa fa-home"></i> <a href="<?php echo getUrl('config/postalCard');?>"> 包邮卡管理  <i class="fa fa-angle-right"></i> </a></li>
                        <li><a href="javascript:;"><?php echo $title?> </a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN FORM-->
                    <form action="<?php echo getUrl('config/postalCard/save');?>" class="form-horizontal" id="model-form" method="post">
                        <div class="form-group">
                            <label class="control-label col-md-2">发放类型</label>
                            <div class="col-md-4">
                                <select name="type" class="form-control">
                                    <?php if(!$add && $info['type'] == 1): ?><option selected value="1">注册发放</option><?php endif;?>
                                    <?php if($add || $info['type'] == 2): ?><option selected value="2">指定用户</option><?php endif;?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-2">名称</label>
                            <div class="col-md-4">
                                <input type="text" name="name" class="form-control required" value="<?php echo !$add ? $info['name'] : ''?>"/>
                            </div>
                            <label class="control-label col-md-2">面额</label>
                            <div class="col-md-4">
                                <input type="text" name="money" class="form-control required" value="<?php echo !$add ? $info['money'] : ''?>" placeholder="请发放面额小于100的包邮卡"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-2">可用天数</label>
                            <div class="col-md-4">
                                <input type="text" name="use_date" class="form-control required" value="<?php echo !$add ? $info['use_date'] : ''?>"/>
                            </div>
                            <label class="control-label col-md-2">每人发放数量</label>
                            <div class="col-md-4">
                                <input type="text" name="send_number" class="form-control required" value="<?php echo !$add ? $info['send_number'] : ''?>"/>
                            </div>
                        </div>
                        <?php  if($info['type']==1): ?>
                            <div class="form-group">
                                <label class="control-label col-md-2">是否启用</label>
                                <div class="col-md-4">
                                    <select name="status" class="form-control">
                                        <option <?php if(!$add && $info['status'] == 1): ?> selected <?php endif;?> value="1">关闭</option>
                                        <option <?php if(!$add && $info['status'] == 2): ?> selected <?php endif;?> value="2">开启</option>
                                    </select>
                                </div>
                            </div>
                        <?php  endif; ?>
                        <div class="form-actionsc fluid">
                            <div class="col-md-offset-2 col-md-9" style="padding-left:0;">
                                <input type="hidden" name="consumer_ids">
                                <input type="hidden" name="id" value="<?php echo !$add ? $info['id'] : ''?>">
                                <button class="btn green submit"><i class="fa fa-save"></i>保存</button>
                            </div>
                        </div>
                    </form>
                    <!-- END FORM-->
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        var model = $('#model-form');
        $('.submit').click(function(){
            var id =$("input[type='checkbox']:checked");
            var vl = $("[name='type']").val();
            if(id.length == 0 && vl == 2)
            {
                show_message({status:0, message:'请选择用户'});
                return false;
            }
            var consumerId = 0;
            id.each(function(){
                if (consumerId == 0){
                    consumerId = $(this).val();
                }else{
                    consumerId += ','+$(this).val();
                }
            });
            model.find('[name="consumer_ids"]').val(consumerId);
        });
        $.e_validate.init('#model-form',{successCallback:function(){
            $('[name="content"]').val('');
            $('[type="submit"]').attr('disabled', false);
            $('[type="checkbox"]').attr('checked', false).uniform();
            $("input").val('');
        }});
    });
</script>
</body>
</html>
